import java.io.File;
import java.io.IOException;

public class zuoye6 {
    public static void main(String[] args) {
       String filePath="D:/MyFolder";
       String fileName="test.txt";
        File myFolder=new File(filePath);
        if (!myFolder.exists()) {
            myFolder.mkdirs();
        }
        File myFile=new File(filePath+"/"+fileName);
        if (!myFile.exists()) {
            try {
                myFile.createNewFile();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        System.out.println("-------------------------------");
        System.out.println("文件绝对路径;"+myFile.getAbsolutePath());
        System.out.println("文件名称："+myFile.getName());
        System.out.println("文件父节点："+myFile.getParent());
        System.out.println("是文件夹吗？"+myFile.isDirectory());
        System.out.println("是文件吗？"+myFile.isFile());
        System.out.println("是隐藏的吗？"+myFile.isHidden());
        System.out.println("是可读的吗？"+myFile.canRead());
        System.out.println("是可写的吗？"+myFile.canWrite());
        System.out.println("是可执行的吗？"+myFile.canExecute());
        System.out.println("最后一次修改时间？"+myFile.lastModified());
        System.out.println("文件的大小："+myFile.length());
        System.out.println("---------------------");

        File[]files=myFile.listFiles();
        System.out.println("文件：");
        for(File file:files){
            if (file.isFile()) {
                System.out.println("\t"+file.getName());
            }
        }
        System.out.println("文件夹：");
        for (File file:files){
            if (file.isDirectory()) {
                System.out.println("\t"+file.getName());
            }
        }
        File[] roots=File.listRoots();
        for (int i = 0; i < roots.length; i++) {
            System.out.println(roots[i]);
            System.out.println("空闲空间："+roots[i].getFreeSpace());
            System.out.println("可用空间："+roots[i].getUsableSpace());
            System.out.println("总空间："+roots[i].getTotalSpace());
            System.out.println();
        }
        System.out.println("------------------------------");
        myFile.delete();
        if (!myFile.exists()) {
            System.out.println("文件删除成功！");
        }
        if (!myFolder.exists()) {
            System.out.println("文件夹删除成功！");
            System.out.println("-----------------");
        }
    }
}
